﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text.RegularExpressions;
using University.Workshop.Business;
using University.Workshop.Model;
using University.Workshop.DataAccess;

namespace University.Workshop.WebApp
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["newUserToLogin"] != null)
                {
                    xEmail.Text = Session["newUserToLogin"].ToString();
                }
            }
        }
        protected void bConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                User user = LogOnManager.LogOn(xEmail.Text, xPassword.Text);
                bool persistent = KeepSignbx.Checked;
                FormsAuthentication.RedirectFromLoginPage(xEmail.Text, persistent);

                user = UserDataAccess.GetUserByEmail(xEmail.Text);
                if (user.Status == AccountState.Inactive)
                {
                    UserCancelAccountManager.ReactiveUserAccount(user);
                    Response.Redirect("ReactivateAccountMessage.aspx");
                }

                
            }
            catch (Exception ex)
            {
                lException.Text = ex.Message;
            }

        }
    }
}